Hierarchy of FastReport classes

TfrxComponent is the basic class for all FastReport components. Objects of this type have such parameters as “coordinates,” “size,” “font,” “visibility,” and lists of subordinate objects. The class also contains methods, which allow to save/restore object’s state to/from the stream.

TfrxComponent = class (TComponent)

protected

procedure SetParent(AParent: TfrxComponent); virtual ;

procedure SetLeft(Value: Extended); virtual ;

procedure SetTop(Value: Extended); virtual ;

procedure SetWidth(Value: Extended); virtual ;

procedure SetHeight(Value: Extended); virtual ;

procedure SetFont(Value: TFont); virtual ;

procedure SetParentFont(Value: Boolean); virtual ;

procedure SetVisible(Value: Boolean); virtual ;

procedure FontChanged(Sender: TObject); virtual ;

public

constructor Create(AOwner: TComponent); override ;

procedure Assign(Source: TPersistent); override ;

procedure Clear; virtual ;

procedure CreateUniqueName;

procedure LoadFromStream(Stream: TStream); virtual ;

procedure SaveToStream(Stream: TStream; SaveChildren: Boolean = True); virtual ;

procedure SetBounds(ALeft, ATop, AWidth, AHeight: Extended);

function FindObject( const AName: String ): TfrxComponent;

class function GetDescription: String ; virtual ;

property Objects: TList readonly;

property AllObjects: TList readonly;

property Parent: TfrxComponent;

property Page: TfrxPage readonly;

property Report: TfrxReport readonly;

property IsDesigning: Boolean;

property IsLoading: Boolean;

property IsPrinting: Boolean;

property BaseName: String ;

property Left: Extended;

property Top: Extended;

property Width: Extended;

property Height: Extended;

property AbsLeft: Extended readonly;

property AbsTop: Extended readonly;

property Font: TFont;

property ParentFont: Boolean;

property Restrictions: TfrxRestrictions;

property Visible: Boolean;

end ;

- Clear – clears object’s contents and deletes all its child objects.

- CreateUniqueName – creates a unique name for an object placed into the report.

- LoadFromStream – loads object contents and all its child objects from the stream.

- SaveToStream – saves an object to the stream. The SaveChildren parameter defines, whether state of all child objects should also be saved.

- SetBounds – sets coordinates and size of an object.

- FindObject – searches for an object with specified name among the child objects.

- GetDescription – returns to the object’s description.

The following methods are called when modifying the corresponding properties. If additional handling is needed, you can override them:

SetParent

SetLeft

SetTop

SetWidth

SetHeight

SetFont

SetParentFont

SetVisible

FontChanged

The following properties are defined in the “TfrxComponent” class:

- Objects – the list of child objects;

- AllObjects – the list of all subordinate objects;

- Parent – link to the parent object;

- Page – link to the report page, which the object belongs to;

- Report – link to the report, which the object belongs to;

- IsDesigning – “True,” if the designer is running;

- IsLoading – “True,” if an object is being loaded from the stream;

- IsPrinting - true, if an object is being printed out;

- BaseName - basic name of an object. This value is used in the “CreateUniqueName” method;

- Left – object’s X coordinate (relatively to a parent);

- Top - object’s Y coordinate (relatively to a parent);

- Width – object’s width;

- Height – object’s height;

- AbsLeft - object’s X absolute coordinate;

- AbsTop - object’s Y absolute coordinate;

- Font – object’s font;

- ParentFont – if “True,” then uses the parent object font settings;

- Restrictions – set of flags, which restrict some object operations;

- Visible – object’s visibility.

The next basic class is TfrxReportComponent. Objects of this type can be placed into a report. The class contains the “Draw” method for object’s painting, as well as “BeforePrint/GetData/AfterPrint” methods, which are called as soon as a report runs.

TfrxReportComponent = class (TfrxComponent)

public

procedure Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX, OffsetY: Extended); virtual ; abstract ;

procedure BeforePrint; virtual ;

procedure GetData; virtual ;

procedure AfterPrint; virtual ;

function GetComponentText: String ; virtual ;

property OnAfterPrint: TfrxNotifyEvent;

property OnBeforePrint: TfrxNotifyEvent;

end;

The Draw method is called when painting an object. The parameters are:

- “Canvas” – canvas;

- “Scale” – zoom by X-axis and Y-axis;

- Offset – offset relatively to the edges of the canvas.

The BeforePrint method is called right before the object is handled (during process of building a report). This method saves object's state.

The GetData method is called to load data into an object.

The AfterPrint is called after the object is handled. The method restores the object's state.

The TfrxDialogComponent class is the basic one for writing non-visual components, which can be placed to a dialogue form in a report.

TfrxDialogComponent = class (TfrxReportComponent)

public

property Bitmap: TBitmap;

property Component: TComponent;

published

property Left;

property Top;

end;

The “TfrxDialogControl” class is the basic one for writing common control, which can be placed to a dialogue form in a report. The class contains a large number of general properties and events shared with most of the common controls.

TfrxDialogControl = class (TfrxReportComponent)

protected

procedure InitControl(AControl: TControl);

public

property Caption: String ;

property Color: TColor;

property Control: TControl;

property OnClick: TfrxNotifyEvent;

property OnDblClick: TfrxNotifyEvent;

property OnEnter: TfrxNotifyEvent;

property OnExit: TfrxNotifyEvent;

property OnKeyDown: TfrxKeyEvent;

property OnKeyPress: TfrxKeyPressEvent;

property OnKeyUp: TfrxKeyEvent;

property OnMouseDown: TfrxMouseEvent;

property OnMouseMove: TfrxMouseMoveEvent;

property OnMouseUp: TfrxMouseEvent;

published

property Left;

property Top;

property Width;

property Height;

property Font;

property ParentFont;

property Enabled: Boolean;

property Visible;

end ;

When writing your own element, you should inherit from this class, transfer required properties into the “published” section, and then specify new properties for your common control. Refer to the corresponding chapter to know more about writing user common controls.

The TfrxView class is the basic one for most components, which can be placed to a report page. An object of this type has such parameters as “Frame” and “Filling,” and also can be connected to the data source. Practically all FastReport standard objects are inherited from this class.

TfrxView = class (TfrxReportComponent)

protected

FX, FY, FX1, FY1, FDX, FDY, FFrameWidth: Integer;

FScaleX, FScaleY: Extended;

FCanvas: TCanvas;

procedure BeginDraw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX, OffsetY: Extended); virtual ;

procedure DrawBackground;

procedure DrawFrame;

procedure DrawLine(x, y, x1, y1, w: Integer);

public

function IsDataField: Boolean;

property BrushStyle: TBrushStyle;

property Color: TColor;

property DataField: String ;

property DataSet: TfrxDataSet;

property Frame: TfrxFrame;

published

property Align: TfrxAlign;

property Printable: Boolean;

property ShiftMode: TfrxShiftMode;

property TagStr: String ;

property Left;

property Top;

property Width;

property Height;

property Restrictions;

property Visible;

property OnAfterPrint;

property OnBeforePrint;

end;

The following methods are defined in the class:

- BeginDraw - the method is called from the “Draw” method and calculates integervalued coordinates and sizes of the object area. The calculated values are presented as “FX,” “FY,” “FX1,” “FY1,” “FDX,” and “FDY” variables. The frame width (it is placed in the FFrameWidth) is also calculated;

- DrawBackground - draws background for an object;

- DrawFrame - draws the object's frame;

- DrawLine(x, y, x1, y1, w: Integer) - draws a line with specified coordinates and width;

- IsDataField returns “True,” if properties of DataSet and DataField contain nonempty values.

One can refer to the following properties after calling the “BeginDraw” method:

- FX, FY, FX1, FY1, FDX, FDY, FFrameWidth are the coordinates, sizes and width of the object's frame, calculated according to the “Scale” and “Offset” parameters;

- “FScaleX” and “FScaleY” are the scales, which are copies of the “ScaleX” and “ScaleY” parameters from the “Draw” method;

- “FCanvas” is a canvas, which is a copy of the “Canvas” parameter from the “Draw” method.

The following properties, being general for most of the report's objects, are defined in the class:

- BrushStyle – object's filling style;

- Color – object's filling color;

- DataField - data field's name, which the object is connected to;

- DataSet - data source;

- Frame - object's frame;

- Align - object's aligning relatively to its parent;

- Printable – defines whether the given object should be printed out;

- ShiftMode is the mode of object's shifting in cases when a stretchable object is placed over the given one;

- TagStr - the field for storing different information.

The TfrxStretcheable class is the basic one for writing components, which modify their height depending on the data placed in it.

TfrxStretcheable = class (TfrxView)

public

function CalcHeight: Extended; virtual ;

function DrawPart: Extended; virtual ;

procedure InitPart; virtual ;

published

property StretchMode: TfrxStretchMode;

end;

Objects of the given class can be not only stretched, but they can also be "broken" into pieces in cases when an object does not find room on the page. At the same time, the object is displayed piecemeal until all its data is displayed.

The following methods are defined in the class:

- CalcHeight is to calculate and return the object's height according to the data placed in it;

- InitPart is called before object's breaking;

- DrawPart redraws the next data chunk, which is placed in the object. A “Return value” is a value of the unused space where it was impossible to display the data.